package com.siruier.boss.ui.dialog

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.siruier.boss.R
import com.siruier.boss.bean.GiftOrderDetailBean
import com.siruier.boss.common.formatPriceRmb
import com.siruier.boss.databinding.DialogHangingSaleBinding
import com.siruier.boss.ui.utils.GlideUtils

class HangingSaleDialog(
    context: Context,
    recoverPrice: String,
    orderDetail: GiftOrderDetailBean,
    cancelListener: () -> Unit,
    hangingSaleListener: () -> Unit,
) : Dialog(context, R.style.dimLoadingdialog) {

    private val vb: DialogHangingSaleBinding = DialogHangingSaleBinding.inflate(LayoutInflater.from(context))

    init {
        setContentView(vb.root)
        GlideUtils.intoRoundedCorners(vb.ivGoods.context, orderDetail.goodsList[0].picUrl, vb.ivGoods, roundingRadius = 5)
        vb.tvGoodsName.text = orderDetail.goodsList[0].goodsName
        vb.tvGoodsMoney.text = recoverPrice

        setOnCancelListener {
            cancelListener.invoke()
        }

        vb.buttonConfirm.setOnClickListener {
            hangingSaleListener.invoke()
            dismiss()
        }

        vb.viewClose.setOnClickListener {
            cancelListener.invoke()
            dismiss()
        }

        val window = window
        val attributes = window!!.attributes
        attributes.width = (context.resources.displayMetrics.widthPixels * 0.868).toInt()
        attributes.height = ViewGroup.LayoutParams.WRAP_CONTENT
        window.attributes = attributes
    }
}